package com.foreknow.demo4;

/**
 * 方法在实际中的应用
 */
public class ExampleMethod {

    /**
     * 根据id删除某个用户的信息
     * delete from user where id=?
     * @param id
     * @return
     */
    public static int deleteById(int id) {
        return 1;
    }

    /**
     * 登录
     * select * from user where username=? and password=?
     * @param username 用户名
     * @param password 密码
     * @return boolean
     */
    public static boolean login(String username,String password) {
        return true;
    }

    /**
     * 查询所有用户的信息
     * select * from user
     * @return String[]
     */
    public static String[] getQueryAll() {
        String[] str = new String[10];
        str[0] = "tom";
        str[1] = "fender";
        return str;
    }

    /**
     * 根据id查询某个用户的信息
     * select * from user where id=?
     * @param id
     * @return String
     */
    public static String getQueryById(int id) {
        return "张三";
    }

    /**
     * 注册
     * insert into user(username,password) values(?,?)
     * @param username
     * @param password
     * @return boolean
     */
    public static boolean register(String username,String password) {
        return false;
    }


    public static void main(String[] args) {
        boolean r = register("tom","123456");
        if(r) {
            System.out.println("insert success......");
        }else {
            System.out.println("insert error......");
        }
        System.out.println("---------------------------根据id查询某个用户的信息---------------------------------");
        String name = getQueryById(1001);
        System.out.println(name);
        System.out.println("---------------------------查询---------------------------------");
        String[] all = getQueryAll();
        for(int i = 0;i<all.length;i++){
            System.out.println(all[i]);
        }
        System.out.println("----------------------------删除--------------------------------");
        int a = deleteById(1001);
        if(a == 1) {
            System.out.println("delete success.....");
        }else {
            System.out.println("delete fail......");
        }
        System.out.println("---------------------------登录---------------------------------");
        boolean isRigth = login("tom","123456");
        if(isRigth) {
            System.out.println("success......");
        }else {
            System.out.println("error......");
        }
        System.out.println("------------------------------------------------------------");
    }


}
